package com.lintf.distributed.transaction;

import com.lintf.distributed.transaction.api.InventoryRPCService;
import com.lintf.distributed.transaction.api.OrderRPCService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ author lintf
 * @ system Mac
 * @ data 2025/7/9
 * @ package_name com.lintf.distributed.transaction
 * @ project_name distributed-transaction
 * @ desc
 */
@RestController
@RequestMapping("/rpc")
public class RPCController {

    @DubboReference(version = OrderRPCService.RPC_VERSION)
    private OrderRPCService orderRPCService;

    @DubboReference(version = InventoryRPCService.RPC_VERSION)
    private InventoryRPCService inventoryRPCService;

    @GetMapping("/order/details")
    private String getOrderDetails(Long orderId) {
        return orderRPCService.getOrderDetails(orderId).toString();
    }

    @GetMapping("/inventory/details")
    private String getInventoryDetails(Long productId) {
        return inventoryRPCService.getInventoryDetail(productId).toString();
    }
}
